#include<iostream>
#include<string>
using namespace std;
const int N = 1e5 + 10;
int n, m;
int arr[N], q[N];
int len = 1;
int find(int x)
{
	int l = 0, r = len + 1;
	while (l + 1 < r) {
		int mid = l + r >> 1;
		if (q[mid] < x)l = mid;
		else r = mid;
	}
	return r;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> arr[i];
	}
	q[1] = arr[1];
	for (int i = 2; i <= n; i++) {
		if (arr[i] > q[len]) {
			q[++len] = arr[i];
			//cout << "len===" << len << endl;
		}
		else {
			int idx = find(arr[i]);
			//cout << "idx===" << idx << endl;
			q[idx] = arr[i];
		}
	}
	cout << len << endl;
	return 0;
}